﻿#pragma once
#include<iostream>
#include<vector>
#include<list>
using namespace std;
namespace QL
{
	//Stack可用的容器有vector , list , deque 
	template<class T,class Container = vector<T>>
	class Stack
	{
	public:
		void push(const T& x)
		{
			_con.push_back(x);
		}
		T& top()
		{
			return _con.back();
		}
		void pop()
		{
			_con.pop_back();
		}
		bool empty() const 
		{
			return _con.empty();
		}
		size_t size() const 
		{
			return _con.size();
		}
	private:
		Container _con;
	};

	void test_stack()
	{
		Stack<int> s;
		s.push(1);
		s.push(2);
		s.push(3);
		s.push(4);
		s.push(5);
	
		while (!s.empty())
		{
			cout << s.top() << " ";
			s.pop();
		}
		cout << endl;

		Stack<int,list<int>> s1;
		s1.push(1);
		s1.push(2);
		s1.push(3);
		s1.push(4);
		s1.push(5);

		while (!s1.empty())
		{
			cout << s1.top() << " ";
			s1.pop();
		}
		cout << endl;
		
	}
}
